<?php
class ControllerCommonHome extends Controller {
	/*public function index() {
		$this->document->setTitle($this->config->get('config_title'));
		$this->document->setDescription($this->config->get('config_meta_description'));

		$this->data['heading_title'] = $this->config->get('config_title');

		$this->language->load('product/category');

		$this->load->model('catalog/product');

		$this->load->model('tool/image');

		if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'p.sort_order';
		}
		
		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'ASC';
		}

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}

		if (isset($this->request->get['limit'])) {
			$limit = $this->request->get['limit'];
		} else {
			$limit = $this->config->get('config_catalog_limit');
		}

		if (isset($this->request->get['path'])) {
			$path = '';

			$parts = explode('_', (string)$this->request->get['path']);

			$category_id = array_pop($parts);
		} else {
			$category_id = 0;
		}

		//Filter product by price
		if (isset($this->request->get['price_id'])) {
			$priceId = $this->request->get['price_id'];
		} else {
			$priceId = '';
		}
		//Filter product by color
		if (isset($this->request->get['color_id'])) {
			$colorId = $this->request->get['color_id'];
		} else {
			$colorId = '';
		}
		
		//Filter product by size
		if (isset($this->request->get['size_id'])) {
			$sizeId = $this->request->get['size_id'];
		} else {
			$sizeId = '';
		}
		
		
		$data = array(
			'filter_category_id' => $category_id, 
			'sort'               => $sort,
			'order'              => $order,
			'start'              => ($page - 1) * $limit,
			'limit'              => $limit,
			'filter_price_id'		 => $priceId,
			'filter_color_id'		 => $colorId,
			'filte_size_id'      => $sizeId
		);

		$this->data['products'] = array();

		$results = $this->model_catalog_product->getProducts($data);

		foreach ($results as $result) {
			if ($result['image']) {
				$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
			} else {
				$image = false;
			}

			if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$price = false;
			}

			if ((float)$result['special']) {
				$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$special = false;
			}

			if ($this->config->get('config_tax')) {
				$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
			} else {
				$tax = false;
			}

			if ($this->config->get('config_review_status')) {
				$rating = (int)$result['rating'];
			} else {
				$rating = false;
			}

			$this->data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'rating'      => $result['rating'],
					'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
					'href'        => $this->url->link('product/product', 'path=' . (isset($this->request->get['path'])?$this->request->get['path']:'') . '&product_id=' . $result['product_id'])
			);
		}

		$url = '';

		if (isset($this->request->get['limit'])) {
			$url .= '&limit=' . $this->request->get['limit'];
		}

		$url = '';

		if (isset($this->request->get['sort'])) {
			$url .= '&sort=' . $this->request->get['sort'];
		}

		if (isset($this->request->get['order'])) {
			$url .= '&order=' . $this->request->get['order'];
		}
		$product_total = $this->model_catalog_product->getTotalProducts($data); 

		$pagination = new Pagination();
		$pagination->total = $product_total;
		$pagination->page = $page;
		$pagination->limit = $limit;
		$pagination->text = '';
		$pagination->url = $this->url->link('common/home', 'path=' . (isset($this->request->get['path'])?$this->request->get['path']:'') . $url . '&page={page}');

		$this->data['pagination'] = $pagination->render();

		$this->data['sort'] = $sort;
		$this->data['order'] = $order;
		$this->data['limit'] = $limit;

		$this->data['continue'] = $this->url->link('common/home');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/home.tpl';
		} else {
			$this->template = 'default/template/common/home.tpl';
		}

		$this->data['button_cart'] = $this->language->get('button_cart');
		
		$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
		);

		$this->response->setOutput($this->render());
	}*/
	public function index() {

    $this->document->setTitle($this->config->get('config_title'));
    $this->document->setDescription($this->config->get('config_meta_description'));

    $this->data['heading_title'] = $this->config->get('config_title');
    
    $this->load->model('catalog/product'); 
    
    $this->load->model('tool/image');

    $this->data['products'] = array();

    $products = explode(',', $this->config->get('featured_product'));

    foreach ($products as $product_id) {
      $product_info = $this->model_catalog_product->getProduct($product_id);
      
      if ($product_info) {
        if ($product_info['image']) {
          $image = $this->model_tool_image->resize($product_info['image'], 200, 200);
        } else {
          $image = false;
        }

        if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
          $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
        } else {
          $price = false;
        }
            
        if ((float)$product_info['special']) {
          $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
        } else {
          $special = false;
        }
        
        if ($this->config->get('config_review_status')) {
          $rating = $product_info['rating'];
        } else {
          $rating = false;
        }
          
        $this->data['products'][] = array(
          'product_id' => $product_info['product_id'],
          'thumb'      => $image,
          'name'       => $product_info['name'],
          'price'      => $price,
          'special'    => $special,
          'rating'     => $rating,
          'reviews'    => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
          'href'       => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
        );
      }
    }

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/common/home.tpl';
    } else {
      $this->template = 'default/template/common/home.tpl';
    }

    $this->data['button_cart'] = $this->language->get('button_cart');
    
    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/header'
    );
    $this->response->setOutput($this->render());
  }
}
?>